<template>
  <div style="width: 100%">
    <div
      style="
        text-align: right;
        font-size: 12px;
        border-bottom: 1px solid #ccc;
        color: #333;
        line-height: 60px;
      "
      id="img"
    >
      <el-button class="ml-5" type="primary" @click="openToSave"
        >新增</el-button
      >
      <el-input
        class="ml-5"
        style="width: 200px"
        placeholder="请输入员工号"
        suffix-icon="el-icon-search"
        v-model="id"
      ></el-input>
      <el-input
        class="ml-5"
        style="width: 200px"
        placeholder="请输入员工姓名"
        suffix-icon="el-icon-search"
        v-model="name"
      ></el-input>
      <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
      <el-button class="ml-5" type="warning" @click="reset">重置</el-button>
    </div>

    <el-main style="padding: 0px 0px">
      <div style="">
        <el-dialog title="员工" :visible.sync="dialogFormVisible">
          <el-form label-width="120px">
            <el-form-item label="员工工号">
              <el-input v-model="adminFrom.id" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="员工姓名">
              <el-input v-model="adminFrom.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="员工科室">
              <el-input
                v-model="adminFrom.department"
                autocomplete="off"
              ></el-input>
            </el-form-item>
            <el-form-item label="员工职业">
              <el-select v-model="adminFrom.job" placeholder="请选择">
                <el-option label="工程师" value="energies"></el-option>
                <el-option label="修理人员" value="requaire"></el-option>
                <el-option label="开发工程师" value="development Engineer"></el-option>
                <el-option label="前端工程师" value="front Engineer"></el-option>
              </el-select>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addAdminInfo">确 定</el-button>
          </div>
        </el-dialog>
      </div>
      <el-table :data="tableData" border >
        <el-table-column prop="id" label="员工号" width="140"></el-table-column>
        <el-table-column prop="name" label="姓名" width="120"></el-table-column>
        <el-table-column prop="department" label="科室"> </el-table-column>
        <el-table-column prop="job" label="职位"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              class="ml-5"
              type="success"
              @click="changAdminInfo(scope.row)"
              >编辑</el-button
            >
            <el-button
              class="ml-5"
              type="danger"
              @click="deleteAdminInfo(scope.row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
    </el-main>
  </div>
</template>
    
  <script>
import qs from "qs";
export default {
  data() {
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 10,
      department: "",
      job: "",
      name: "",
      id: "",
      dialogFormVisible: false,
      adminFrom: {},
    };
  },
  methods: {
    load() {
      this.request
        .get("/EmployeeInfo/page", {
          params: {
            pageNum: this.pageNum,
            pageSize: this.pageSize,
            name: this.name,
            id: this.id,
          },
        })
        .then((req) => {
          this.tableData = req.records;
          this.total = req.total;
        });
    },
    reset() {
      (this.id = ""), (this.name = ""), this.load();
    },
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.load();
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum;
      this.load();
    },
    changAdminInfo(row) {
      this.adminFrom = row;
      this.dialogFormVisible = true;
    },
    deleteAdminInfo(id) {
      this.request.delete("/EmployeeInfo/delete/" + id).then((res) => {
        if (res) {
          this.$message.success("删除成功");
          this.dialogFormVisible = false;
          this.reset();
        } else {
          this.$message.error("删除失败");
        }
      });
    },
    addAdminInfo() {
      // console.log(this.adminFrom);
      this.$axios
        .post("/EmployeeInfo/saveEmployeeInfo", qs.stringify(this.adminFrom))
        .then((res) => {
          console.log(res)
          if (res.data) {
            this.$message.success("新增成功");
            this.dialogFormVisible = false;
            this.reset();
          } else {
            this.$message.error("新增失败");
          }
        });
    },
    openToSave() {
      (this.dialogFormVisible = true), (this.adminFrom = []);
    },
  },
  created() {
    this.load();
  },
};
</script>
<style>
.el-header {
  /* background-color: #b3c0d1; */
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}

#img{
  background-image: url(@/img/admin.jpg);
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: fixed;
  background-size: cover;
}
</style>
